package com.work.keep.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.work.keep.R;
import com.work.keep.application.MyApplication;
import com.work.keep.base.BaseActivity;
import com.work.keep.datas.FragmentOtherDynamicData;
import com.work.keep.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/24.
 */
public class BigPhotoActivity extends BaseActivity {
    private ViewPager bigPhotoViewPager;
    private ImageView bigPhotoLeft;
    private TextView bigPhotoContent, bigPhotoPraiseText, bigPhotoReplyText, bigPhotoDetails;
    private static List<FragmentOtherDynamicData.DataEntity> dataEntitys;
    private ImageLoader imageLoader;
    private static int position;

    public static void goToBigPhotoActivity(Context context,List<FragmentOtherDynamicData.DataEntity> dataEntitys, int position) {
        Intent intent = new Intent(context, BigPhotoActivity.class);
        BigPhotoActivity.dataEntitys = dataEntitys;
        BigPhotoActivity.position = position;
        context.startActivity(intent);
    }

    @Override
    protected View getLayoutView() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_big_photo;
    }

    @Override
    protected void initView() {
        bigPhotoViewPager = (ViewPager) findViewById(R.id.bigPhotoViewPager);
        bigPhotoLeft = (ImageView) findViewById(R.id.bigPhotoLeft);
        bigPhotoContent = (TextView) findViewById(R.id.bigPhotoContent);
        bigPhotoPraiseText = (TextView) findViewById(R.id.bigPhotoPraiseText);
        bigPhotoReplyText = (TextView) findViewById(R.id.bigPhotoReplyText);
        bigPhotoDetails = (TextView) findViewById(R.id.bigPhotoDetails);
    }

    @Override
    protected void initData() {
        imageLoader = VolleySingleton.getInstance()._getImageLoader();
        bigPhotoViewPager.setAdapter(new PagerAdapter() {
            @Override
            public int getCount() {
                return dataEntitys.size();
            }

            @Override
            public Object instantiateItem(ViewGroup container, final int position) {
                View v = LayoutInflater.from(container.getContext()).inflate(R.layout.item_activity_big_photo, container, false);
                NetworkImageView networkImageView = (NetworkImageView) v.findViewById(R.id.bigPhotoPhoto);
                networkImageView.setDefaultImageResId(R.mipmap.plan320_160);
                networkImageView.setErrorImageResId(R.mipmap.plan320_160);
                networkImageView.setImageUrl(dataEntitys.get(position).getPhoto(), imageLoader);
                bigPhotoContent.setText(dataEntitys.get(position).getContent());
                bigPhotoPraiseText.setText(dataEntitys.get(position).getLikes() + "");
                bigPhotoReplyText.setText(dataEntitys.get(position).getComments() + "");
                bigPhotoDetails.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        DynamicDetailsActivity.goToDynamicDetailActivity(BigPhotoActivity.this, dataEntitys.get(position).get_id());
                    }
                });
                container.addView(v);
                return v;
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
        });
        bigPhotoViewPager.setCurrentItem(position);
        bigPhotoLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
